package com.aibaixun.common.utils;

import org.apache.commons.lang3.RandomStringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zhangyh
 * @date 2023-02-14
 **/
public class CommonUtils {

    /**
     * 获取批次号
     * @return
     */
    public static String getBatchNo() {
        String timeString = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        String randomString = RandomStringUtils.randomNumeric(8);
        return timeString+randomString;
    }

    /**
     * 数据去重
     * @param str
     * @return
     */
    public static String[] checkArr(String[] str) {
        List<String> list = new ArrayList<String>();
        for (int i = 0; i < str.length; i++) {
            if (!list.contains(str[i])) {
                list.add(str[i].trim());
            }
        }
        // 返回一个包含所有对象的指定类型的数组
        String[] newStr = list.toArray(new String[1]);
        return newStr;
    }
}
